-
-
Notifications
You must be signed in to change notification settings - Fork 210
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
OpenApi : nested ref in #/components/schemas/ #472
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
But I would wait for @Eomm comment before merging. He has better understanding on how the $ref
works on OpenAPI standard and how to resolve it correctly.
@@ -319,9 +319,22 @@ function prepareOpenapiMethod (schema, ref, openapiObject) { | |||
return openapiMethod | |||
} | |||
|
|||
function prepareOpenapiSchemas (schemas, ref) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you describe what you need to archive here?
I'm not sure to fully understand
With some testing this is not working if I put additional schemas in the bottom test:
instance.addSchema({ $id: 'OrderItem', type: 'object', properties: { id: { type: 'integer' } } })
+ instance.addSchema({ $id: 'ProductItem', type: 'object', properties: { id: { type: 'integer' } } })
instance.addSchema({ $id: 'Order', type: 'object', properties: { products: { type: 'array', items: { $ref: 'OrderItem' } } } })
instance.post('/', { schema: { body: { $ref: 'Order' }, response: { 200: { $ref: 'Order' } } } }, () => {})
+ instance.post('/other', { schema: { body: { $ref: 'ProductItem' } } }, () => {})
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi Ecomm, I d'like to replace local $ref
with local openapi components schema (prefixed by #/components/schemas/
) in generated openapi components schema.
With that change, openapi components will be able to reference other local components.
I wrote a simple test of my use case (too simple may be) and I pick the function from cjsewell@1a816ee which seems to work well on my test.
I going to improve my test (with a more complex case, has you done). In try too investigate why the test hang when you add other schema definitions.
Do you have a better idea on that function implementation?
Thx
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have investigated on hanging test you where face to.
I seems to be cause by unfinished fastify-swagger initialization whereas fastify fastify.ready()
is ok.
I have rewrote test using async/await to provide more readable tests and I never have this trouble anymore.
Hanging test behavior also exists on your test case without pull request feature.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Like @Eomm mentionned we need to add more test with complexe routing + schemas to try to detect any collision we might have.
Thinking out loud: Isn't the petstore a good playground for this kind of test? https://petstore3.swagger.io/api/v3/openapi.json
rewrite test using await/async to be more readable
Pull Request Test Coverage Report for Build 1270352819
💛 - Coveralls |
@zekth I provide a more complex test case of nested ref in schema definitions. fastify-swagger/test/spec/openapi/refs.js Lines 60 to 86 in 2f28ad6
Thx for your review. Best regards |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good job on this.
Thank you all |
Checklist
npm run test
andnpm run benchmark
Fix #462